package com.asf.sofom.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.asf.sofom.domain.OBancos;

@Repository(value = "bancosDao")
public class JPABancos implements BancosDao{

	private EntityManager em = null;
	
	@PersistenceContext
	public void setEntityManager(EntityManager em){
		this.em = em;
	}
	
	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")	
	public List<OBancos> getBancos() {
		TypedQuery<OBancos> tq = (TypedQuery<OBancos>) em.createNativeQuery("Select * from bancos", OBancos.class);
		List<OBancos> lb = tq.getResultList();
		return lb;
	}

	@Transactional(readOnly = false)
	public void setBancos(OBancos banco) {
		em.merge(banco);
	}

}
